package io.renren.modules.rps.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.renren.common.constant.Constant;
import io.renren.common.page.PageData;
import io.renren.common.service.impl.BaseServiceImpl;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.rps.dao.CenterMonthDao;
import io.renren.modules.rps.dto.CenterDailyDTO;
import io.renren.modules.rps.dto.CenterMonthDTO;
import io.renren.modules.rps.entity.CenterDailyEntity;
import io.renren.modules.rps.entity.CenterMonthEntity;
import io.renren.modules.rps.service.CenterMonthService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 中心月报管理
 *
 * @author HuYJ huyongjie@qone-inst.com
 * @since 1.0.0 2022-10-18
 */
@Service
public class CenterMonthServiceImpl extends BaseServiceImpl<CenterMonthDao, CenterMonthEntity> implements CenterMonthService {


    @Override
    public PageData<CenterMonthDTO> page(Map<String, Object> params) {
        //分页
        IPage<CenterMonthEntity> page = getPage(params, Constant.CREATE_DATE, false);

        //查询
        List<CenterMonthEntity> list = baseDao.getList(params);

        return getPageData(list, page.getTotal(), CenterMonthDTO.class);
    }

    @Override
    public List<CenterMonthDTO> list(Map<String, Object> params) {
        //查询
        List<CenterMonthEntity> entityList = baseDao.getList(params);

        return ConvertUtils.sourceToTarget(entityList, CenterMonthDTO.class);
    }

    @Override
    public CenterMonthDTO get(Long id) {
        CenterMonthEntity entity = baseDao.getById(id);

        return ConvertUtils.sourceToTarget(entity, CenterMonthDTO.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(CenterMonthDTO dto) {
        CenterMonthEntity entity = ConvertUtils.sourceToTarget(dto, CenterMonthEntity.class);

        insert(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(CenterMonthDTO dto) {
        CenterMonthEntity entity = ConvertUtils.sourceToTarget(dto, CenterMonthEntity.class);

        //更新日报数据
        updateById(entity);
    }


    @Override
    public void delete(Long[] ids) {
        //删除日报数据
        baseDao.deleteBatchIds(Arrays.asList(ids));
    }
}